<%
local baud = luci.http.formvalue("baud") or ""
local parity = luci.http.formvalue("parity")  or ""
local dbits = luci.http.formvalue("dbits") or ""
local sbits = luci.http.formvalue("sbits") or ""
data = ""  
data = data.."\"".."baudRate".."\":"..tostring(baud) ..","
data = data.."\"".."parity".."\":"..tostring(parity) ..","
data = data.."\"".."dataBits".."\":"..tostring(dbits) ..","
data = data.."\"".."stopBits".."\":"..tostring(sbits) ..","
data=string.sub(data,0,-2)
luci.sys.exec("ubus call szTT_uart_4 uartParameters_set  \'{"..data.."}\'")
%>
<%
require "ubus"
require "uloop"
local util = require "luci.util"
uloop.init()
local conn=ubus.connect() if not  conn then
	error("failed to connect to ubused")    
end
local t_uartPara=conn:call("szTT_uart_4","uartParameters",{})
local uartPara = util.t2j(t_uartPara)
%>

<%+header%>                                                                  
<div class="RS485Containers">
    <div class="gorgeLine">
        <div class="title">
            <span>485串口配置</span>
        </div>
        <div class="titLine"></div>
	<form method="post" action="<%=REQUEST_URI%>" enctype="multipart/form-data" id="RS485Form">
        <table class="gorgeLineTab">
            <tr class="DHCPClient">
                <td class="">通信波特率</td>
                <td>
                    <select name="baud" class="gorgeLineSelect">
                        <option value="3">4800</option>
                        <option value="4">9600</option>
						<option value="5">19200</option>
						<option value="6">38400</option>
						<option value="7">57600</option>
						<option value="8">115200</option>
                    </select>
                </td>
            </tr>
            <tr class="">
                <td class="">校验</td>
                <td>
                    <select name="parity" class="gorgeLineSelect">
						<option value="1">NONE</option>
						<option value="2">EVEN</option>
						<option value="3">ODD</option>
				    </select>
                </td>
            </tr>
            <tr class="">
                <td class="">数据位</td>
                <td>
                    <select name="dbits" class="gorgeLineSelect">
						<option value="6">6</option>
						<option value="7">7</option>
						<option value="8">8</option>
		   			 </select>
                </td>
            </tr>
            <tr class="">
                <td class="">停止位</td>
                <td>
                    <select name="sbits" class="gorgeLineSelect">
						<option value="1">1</option>
						<option value="2">1</option>
		    		</select>
                </td>
            </tr>
        </table>
        <div class="glSubmit">
            <button type="submit" class="layui-btn-normal glSetting">配置</button>
        </div>
	</form>
    </div>
</div>
<script>
var para = <%=uartPara%> 
console.log(para)
	var gorge = $(".gorgeLineSelect");
	$(gorge[0]).val(para.baudRate);
	$(gorge[1]).val(para.parity);
	$(gorge[2]).val(para.dataBits);
	$(gorge[3]).val(para.stopBits);

    $('.glSetting').on('click',function () {
        registPost();
        event.preventDefault();
    });

    function registPost () {
        $.ajax({
            type: "post",
            url: "<%=REQUEST_URI%>",
            data: $('#RS485Form').serialize()
        }).success(function(message) {
            console.log(message);
			window.location.reload();
        }).fail(function(err){
            console.log(err);
        })
    }
</script>
<%+footer%>